#{extends 'main.html' /} 
#{set title:'Criar Consulta' /}

#{form @Atendentes.criarConsulta(), class:'form-horizontal well'}

<div class="control-group #{ifError 'consulta.dataHora'}error#{/ifError}">
	<label class="control-label">Data:</label>
	<div class="controls">
		<input type="text" name="consulta.dataHora" value="${consulta?.dataHora?.format('dd/MM/yyyy HH:mm')}">
		<span class="help-inline">${errors.forKey('consulta.dataHora')}<br/>		Use o formato: dia/mes/ano hora:minuto:segundo
		</span>
	</div>
</div>

<div class="control-group #{ifError 'consulta.dentista'}error#{/ifError}">
	<label class="control-label">Dentista:</label>
	<div class="controls">
		#{select 'consulta.dentista.id', items:dentistas, valueProperty:'id', labelProperty:'nome'/}
		<span class="help-inline">
		${errors.forKey('consulta.dentista')}</span>
	</div>
</div>

<div class="control-group #{ifError 'consulta.paciente'}error#{/ifError}">
	<label class="control-label">Paciente:</label>
	<div class="controls">
		#{select 'consulta.paciente.id', items:pacientes, valueProperty:'id', labelProperty:'nome'/}
		<span class="help-inline">
		${errors.forKey('consulta.paciente')}</span>
	</div>
</div>

<div class="control-group #{ifError 'consulta.procedimento'}error#{/ifError}">
	<label class="control-label">Procedimento:</label>
	<div class="controls">
		#{select 'consulta.procedimento.id', items:procedimentos, valueProperty:'id', labelProperty:'nome'/}
		<span class="help-inline">
		${errors.forKey('consulta.procedimento')}</span>
	</div>
</div>

<div class="">
	<button type="submit" class="btn btn-success">Criar consulta</button>
</div>

#{/form}



#{title text:'Próximas Consultas'/}


<div>
		
			#{if !consultas.empty}
		
			<table class="table table-striped table-bordered table-condensed">
				<thead>
					<tr>
						<th>Data</th>
						<th>Dentista</th>
						<th>Paciente</th>
						<th>Ações</th>
					</tr>
				</thead>
				<tbody>
					#{list items:consultas, as: 'consulta'}
					<tr>
						<td>${consulta.dataHora.format('dd/MM/yyyy HH:mm')}</td>
						<td>${consulta.dentista.nome}</td>
						<td>${consulta.paciente.nome}</td>
						<td><a href="@{atendentes.cancelaConsulta(consulta.id)}"
							class="icon-remove"  onclick="return confirm('Confirma?')"></a></td>
					</tr>
					#{/list}
				</tbody>
			</table>
			
			#{/if}
			
		</div>




